package com.hotel.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.hotel.bean.Regist;
import com.hotel.service.UserService;
import com.hotel.service.impl.UserServiceImpl;
import com.hotel.util.BaseServlet;



@WebServlet("/HomeServlet")
public class HomeServlet extends BaseServlet {
	private static final long serialVersionUID = 1L;
	
	//杨路瑶
	public String ui(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		String pid = null;
		Cookie[] cookies = request.getCookies();
		if (cookies != null) {
			for (Cookie cookie : cookies) {
				if (cookie.getName().equals("pid") && cookie.getMaxAge() > 0) {
					pid = cookie.getValue();
				}
			}
		}
		
		if (pid != null) {
			UserService userService = new UserServiceImpl();
			Regist user = userService.queryById(pid);
			request.getSession().setAttribute("user", user);
		}
		
	
		return "/user/index.jsp";	
	}


}
